package com.hy.controller;

import com.hy.Result.ResponseResult;
import com.hy.medicine.region.City;
import com.hy.medicine.region.District;
import com.hy.medicine.region.Province;
import com.hy.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/region")
public class RegionController {
    @Autowired
    private RegionService regionService;

    /**
     * 获取所有省份
     * @return
     */
    @GetMapping("/provinces")
    public ResponseResult<List<Province>> getAllProvinces() {
        return ResponseResult.okResult(regionService.getAllProvinces());
    }

    /**
     * 根据省份ID获取城市列表
     * @param provinceId
     * @return
     */
    @GetMapping("/cities/{provinceId}")
    public ResponseResult<List<City>> getCitiesByProvinceId(@PathVariable Integer provinceId) {
        return ResponseResult.okResult(regionService.getCitiesByProvinceId(provinceId));
    }

    /**
     * 根据城市ID获取区县列表
     * @param cityId
     * @return
     */
    @GetMapping("/districts/{cityId}")
    public ResponseResult<List<District>> getDistrictsByCityId(@PathVariable Integer cityId) {
        return ResponseResult.okResult(regionService.getDistrictsByCityId(cityId));
    }
}
